package com.yyg.ssm.mapper;

import com.yyg.ssm.domain.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: 一一哥
 * @Blame: yyg
 * @Since: Created in 2021/1/6
 * @Description: $cursor$
 *
 * SQL查询3要素:
 * 1.要查询什么?
 * 2.从哪些表中查?
 * 3.查询条件是什么?
 *
 */
public interface UserMapper {

    @Select("select id,username,password from t_user where username=#{username}")
    List<User> findUserByName(@Param("username") String username);

    /**
     * 根据用户id查询对应的角色
     */
    @Select("SELECT r.role FROM t_role r INNER JOIN t_user_role ur ON ur.role_id=r.id WHERE ur.user_id=#{uid}")
    List<String> selectRolesByUid(@Param("uid") Integer uid);

    @Select("SELECT p.permission FROM t_permission p INNER JOIN t_role_permission rp ON rp.permission_id=p.id INNER JOIN t_user_role ur ON ur.role_id=rp.role_id WHERE ur.user_id=#{uid}")
    List<String> selectPermissionsByUid(@Param("uid") Integer uid);

}
